let baseUrl = "http://localhost:3000"; //配置一个baseURL可以传相对路径
function http(option) {
	let { url, method = "GET", data = {} } = option; //配置项 默认值
	return new Promise((res, rej) => {
		wx.request({
			url: baseUrl + url, //路径拼接
			method: method.toUpperCase(), //忽略大小写
			data, //数据
			success(data) {
				res(data.data);
			},
			fail(err) {
				rej(err);
			},
		});
	});
}
//post请求
http.post = function (url, data) {
	return http({ url: url, data: data, method: "POST" });
};
//get请求
http.get = function (url, data) {
	return http({ url: url, data: data, method: "GET" });
};
export default http;
